using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.UI;

namespace MyControls.DataSources.CompositeHierarchicalDataSource {
    /// <summary>
    /// <see cref="IHierarchicalEnumerable"/> implementation for <see cref="CompositeHierarchicalDataSource"/>.
    /// </summary>
    public class CompositeHierarchicalEnumerable : IHierarchicalEnumerable {
        DataRow[] _rows;

        internal CompositeHierarchicalEnumerable(DataRow[] rows) {
            _rows = rows;
        }

        #region IHierarchicalEnumerable Members

        IHierarchyData IHierarchicalEnumerable.GetHierarchyData(object enumeratedItem) {
            return (IHierarchyData)enumeratedItem;
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator IEnumerable.GetEnumerator() {
            foreach (DataRow row in _rows) {
                yield return new CompositeHierarchyData(row);
            }
        }

        #endregion
    }
}